package com.denlaku.longan.http;

import com.github.pagehelper.Page;

import java.util.List;

/**
 * controller返回值工具类
 *
 * @author tianx
 */
public class Resp {

    public static <T> Return<T> success() {
        return success((T) null, null);
    }

    public static <T> Return<T> success(T data) {
        return success(data, null);
    }

    public static <T> Return<T> message(String message) {
        return success((T) null, message);
    }

    public static <T> Return<T> success(T data, String message) {
        return new Success<>(data, message);
    }

    public static <T> Return<List<T>> success(List<T> data, String message) {
        if (data instanceof Page) {
            return new PageSuccess<>(data, message);
        }
        return new Success<>(data, message);
    }

    public static <T> Return<List<T>> success(List<T> data) {
        return success(data, null);
    }

    public static <T> Return<T> error(String message) {
        return error(message, null);
    }

    public static <T> Return<T> error(String message, Object data) {
        return new com.denlaku.longan.http.Error<>(message, data);
    }

}
